package dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import util.DBHelper;
import orm.IndividualTeachingPlan;

public class IndividualTeachingPlanDAO {
	
	
	public IndividualTeachingPlan getITPByTPID(String tpid) throws SQLException {
		Connection conn = DBHelper.getConnection();
		Statement stmt;
		ResultSet rs;
		
		IndividualTeachingPlan itp = new IndividualTeachingPlan();
		stmt = conn.createStatement();
		rs = stmt.executeQuery("select * from individualteachingplan where TPID ='" + tpid + "'");
		while (rs.next()) {
			int i = 1;
			itp.setTpID(rs.getString(i++));
			itp.setCurrentHearingAge(rs.getString(i++));
			itp.setCurrentLanguageAge(rs.getString(i++));
			itp.setCurrentCognizanceAge(rs.getString(i++));
			itp.setCurrentAge(rs.getString(i++));
			itp.setAggrandizementDomain(rs.getInt(i++));
			itp.setCorePurpose(rs.getInt(i++));
			itp.setActivityPreparation(rs.getString(i++));
			itp.setTeachingWay(rs.getInt(i++));
			itp.setTeachingTime(rs.getString(i++));
			itp.setTeacherAssignment(rs.getString(i++));
			itp.setParentsAssignment(rs.getString(i++));
			itp.setActivityStepReporting(rs.getString(i++));
			itp.setTeachingMaterial(rs.getString(i++));
			itp.setTeacherExperience(rs.getString(i++));
			itp.setParentsBemusement(rs.getString(i++));
			itp.setInstructionSuggestion(rs.getString(i++));
		}
		
		rs.close();
		stmt.close();
		conn.close();
		return itp;
	}
	
	public void insertITP(Statement statement, IndividualTeachingPlan itp) throws SQLException {
		statement.execute("insert into individualteachingplan values('" + itp.getTpID() + "', '" + 
				itp.getCurrentHearingAge() + "', '" + itp.getCurrentLanguageAge() + "', '" + 
				itp.getCurrentCognizanceAge() + "', '" + itp.getCurrentAge() + "', '" + itp.getAggrandizementDomain() + "', '" +
				itp.getCorePurpose() + "', '" + itp.getActivityPreparation() + "', " +
				itp.getTeachingWay() + ", '" + itp.getTeachingTime() + "', '" + 
				itp.getTeacherAssignment() + "', '" + itp.getParentsAssignment() + "', '" +
				itp.getActivityStepReporting() + "', '" + itp.getTeachingMaterial() + "', '" +
				itp.getTeacherExperience() + "', '" + itp.getParentsBemusement() + "', '" +
				itp.getInstructionSuggestion() + "')");
		
	}
	
	public void deleteITP(Statement statement, String tpid) throws SQLException {
		statement.execute("delete from individualteachingplan where TPID = '" + tpid + "'");
	}

	public void updateITP(Statement statement, IndividualTeachingPlan itp) throws SQLException {
		statement.execute("update individualteachingplan set CurrentHearingAge ='" + itp.getCurrentHearingAge() + "', CurrentLanguageAge = '" + 
				itp.getCurrentLanguageAge() + "', CurrentCognizanceAge ='" + itp.getCurrentCognizanceAge() + 
				"', CurrentAge = '" + itp.getCurrentAge() + "', AggrandizementDomain = '" + itp.getAggrandizementDomain() + 
				"', CorePurpose = '" + itp.getCorePurpose() + "', ActivityPreparation = '" + 
				itp.getActivityPreparation() + "', TeachingWay = " + itp.getTeachingWay() + 
				", TeachingTime = '" + itp.getTeachingTime() + "', TeacherAssignment = '" + 
				itp.getTeacherAssignment() + "', ParentsAssignment = '" + itp.getParentsAssignment() + 
				"', ActivityStepReporting = '" + itp.getActivityStepReporting() + "', TeachingMaterial = '" + 
				itp.getTeachingMaterial() + "', TeacherExperience = '" + itp.getTeacherExperience() + 
				"', ParentsBemusement = '" + itp.getParentsBemusement() + "', InstructionSuggestion = '" +
				itp.getInstructionSuggestion() + "' where TPID = '" + itp.getTpID() + "'");
	}
}
